#include<string>
#include<iostream>
#include<queue>
using namespace std;
int a[3001];
struct node
{
	int time,num;
	friend bool operator<(node a,node b)
	{
		if(a.time==b.time)return a.num>b.num;
		else return a.time>b.time;
	}
};
int main()
{
	string s;
	int count=0,qnum,per,k;
	priority_queue<node>pq;
	while(cin>>s,s=="Register")
	{
		cin>>qnum>>per;
		a[qnum]=per;
		node x;
		x.time=per;
		x.num=qnum;
		pq.push(x);
	}
	cin>>k;
	for(int i=1;i<=k;i++)
	{
		node x=pq.top();
		pq.pop();
		cout<<x.num<<endl;
		node y=x;
		y.time+=a[x.num];
		pq.push(y);
	}
	return 0;
}


